package cn.hairui.blog.repository;

import cn.hairui.blog.mapper.BookMapper;
import cn.hairui.blog.model.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @author lihairui
 * @version V1.0
 * @date: 2019/7/28 22:16
 */
@Repository
public class BookRepository {

    @Autowired
    private BookMapper bookMapper;

    public List<Book> findLimited(int start, int end) {
        return bookMapper.findLimited(start, end);
    }

    public Book find(int id) {
        return bookMapper.find(id);
    }

    public List<Map> listMgr() {
        return bookMapper.listMgr();
    }

    public int add(Book book) {
        bookMapper.insert(book);
        return book.getId();
    }

    public List<Book> findByBookName(String bookName) {
        return bookMapper.findByBookName(bookName);
    }

    public void delete(int id) {
        bookMapper.deleteById(id);
    }

    public List<Book> list() {
        return bookMapper.list();
    }

    public void updateCover(Integer id, String fileName) {
        bookMapper.updateCover(id, fileName);
    }
}
